package dao;

import pojo.Student;
import utils.DataConn;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class cha {
    public List<Student> StduentAll(){
        Connection conn = DataConn.getConn();
         ArrayList<Student> list = new ArrayList<>();
         String sql="select *from student";
        try {
             PreparedStatement ps = conn.prepareStatement(sql);
             ResultSet res = ps.executeQuery();
             while (res.next()){
                  Student student = new Student();
                 student.setSid(res.getString(1));
                 student.setSname(res.getString(2));
                 student.setSsex(res.getString(3));
                 student.setSphone(res.getString(4));
                 student.setSage(res.getInt(5));

              list.add(student);
             }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
return list;
    }

}
